{% extends "personal_center/base.html" %}
{% load state_display %}

{% block page_link %}
<link rel="stylesheet" href="../../static/system_setup/css/style.css">
<script src="../../static/system_setup/js/base.js"></script>
<link rel="stylesheet" type="text/css" href="../../static/personal_center/css/index.css">
<link rel="stylesheet" type="text/css" href="../../static/personal_center/css/common.css">
<script type="text/javascript" src="../../static/personal_center/js/index.js"></script>
{% endblock %}


{% block style %}
<style>
    .add_class {
        background: #1E90FF;
    }
    .tab_top {
        width: 100px;height: 40px;line-height: 40px;text-align: center;display: inline-block;cursor: pointer;
    }
</style>
{% endblock %}


{% block right_content %}
<div style="display: inline-block;vertical-align: top;width: 100%;height: 100%;">
    <div class="headline">
        <div id="document_addressee_details_tab" class="tab_top">
            我的申请
        </div>
        <div style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;">
            <button style="height: 30px;width: 90%;background: #0070c1;color: #ffffff;border-radius: 3px" id="add_station"
                    type="button"
                    class="btn btn-default add-station"
                    onclick="javascrtpt:window.location.href='/finance/data_export_index.html'">
                新增
            </button>
        </div>
    </div>
    <!--确认删除？-->
    <div class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm" style="margin-top: 20%;">
            <div class="modal-content" style="height: 100px;border-radius: 7px;width: 300px;background: #F8F8FF;">
                <div class="modal-body" style="height: 50px;line-height: 50px;text-align: center;">
                    <p id="Confirm-content" style="margin-left: 2%;letter-spacing:1px;"></p>
                </div>
                <div class="modal-footer" style="height: 40px;">
                    <button id="close-model2" type="button" class="btn btn-secondary" data-dismiss="modal"
                            style="height: 30px;line-height: 30px;border-radius: 3px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;取&nbsp;消&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </button>
                    <button type="button" class="btn btn-primary"
                            style="margin-left: 2%;margin-right: 2%;height: 30px;line-height: 30px;border-radius: 3px;"
                            onclick="DeleteData()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确&nbsp;认&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div id="my_application" style="width: 100%;height: 95.3%;overflow: auto;background-color: white;">
        <div class="right-box" style="width: 100%;height: 100%;margin-top: 0;">
            <div style="height: 100%;width: 100%;overflow: auto;border-bottom: #cccccc solid 1px;background-color: white;">
                <section class="grid-main" style="height: 100%;">
                    <table id="main_table"></table>
                </section>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block script %}
<script type="text/javascript" src="../../static/administrative/js/layer.js"></script>
<script>
    window.onload = function () {
        document.getElementById("loading").style.display = "none";
        document.getElementById("personage").className = "add_class";
        document.getElementById("sponsor").className = "add-nav-active";
    };

    const gridManagerName = "test",
        TYPE_MAP = {1: "HTML/CSS", 2: "nodeJS", 3: "javaScript", 4: "前端鸡汤", 5: "PM Coffee", 6: "前端框架", 7: "前端相关"},
        arg = {
            gridManagerName: "test",
            width: "100%",
            height: "100%",
            autoOrderConfig: {fixed: "left"},
            checkboxConfig: {key: "id", fixed: "left"},
            supportAjaxPage: !0,
            sortMode: "single",
            supportMenu: !0,
            menuHandler: e => (e.unshift({
                content: "自定义菜单", line: !0, onClick: e => {
                    alert(e)
                }
            }), e),
            useCellFocus: !0,
            useHideRow: !0,
            supportMoveRow: !0,
            moveRowConfig: {
                key: "priority", useSingleMode: !0, fixed: "left", handler: (e, t) => {
                    console.log(e, t)
                }
            },
            disableCache: !1,
            ajaxData: function (e, t) {
                var local_host = window.location.host;          // 获取当前IP
                return "/finance/data_export_list.html"
            },
            exportConfig: {
                fileName: e => {
                    const t = new Date;
                    let a = `${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()}`;
                    for (let t in e) a = `${a}-${t}=${e[t]}`;
                    return a
                }, suffix: "xls"
            },
            ajaxType: "POST",
            checkedBefore: function (e, t, a) {
                return console.log("checkedBefore==", e, t, a), a && 90 === a.id && alert("该节点在checkedBefore中配置为不可选"), a && 90 !== a.id
            },
            responseHandler: e => (e.data.forEach((e => {
                e.priority = e.id
            })), e),
            rowRenderHandler: (e, t) => e,
            emptyTemplate: e => `<div style="text-align: center;">${e.query.title ? "搜索为空" : "暂无数据"}</div>`,
            columnData: [
                {
                    key: "application_reason",
                    text: "申请理由",
                    align: "center",
                    disableMoveRow: !0
                }, {
                    key: "data_type",
                    text: "数据类型",
                    align: "center",
                }, {
                    key: "date",
                    text: "申请时间",
                    align: "center",
                }, {
                    key: "state",
                    text: "状态",
                    align: "center",
                }, {
                    key: "current_audit_users",
                    text: "审批人",
                    align: "center",
                }, {
                    key: "action",
                    width: "100px",
                    align: "center",
                    fixed: "right",
                    disableMoveRow: !0,
                    disableRowCheck: !0,
                    text: '<span style="color: red">操作</span>',
                    template: (e, t) => `<a class="plugin-action" id="${t.id}" href="javascript:;" onclick="">${t.url}</a>`
                }]
        }, demo1 = {
            initSearch: function () {
            }, initFN: () => {

            }, initGM: function () {
                new window.GridManager(table, arg, (e => {
                    console.log("渲染完成后的回调函数:", e), console.log(arg.columnData)
                }))
            }, editRowData: function (e) {
                window.GridManager.updateRowData("test", "id", {
                    id: window.parseInt(e.getAttribute("data-id")),
                    lastDate: (new Date).getTime()
                })
            }
        }, table = document.querySelector("#main_table");
    demo1.initSearch(table), demo1.initGM(table), demo1.initFN();

    const table_name = '{{ table_name }}'

    function del_draft(id_0) {
        var id = id_0
        var r = confirm("确认删除？")
        if (r === true) {
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/data_export_stop", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + id + "&type=delete");
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        alert(JsonDate['message'])
                        window.location.reload();
                    }
                }
            };
        }
        {#var myArray = []#}
        {#myArray.push(id_0)#}
        {#document.getElementById("Confirm-content").innerHTML = "确认要删除这1个草稿吗？"#}

    }

    function ConfirmDelete() {
        var myArray = []
        var check_box_list = document.getElementsByClassName("gm-radio-checkbox-input gm-checkbox-input");
        for (var t = 0; t < check_box_list.length - 1; t++) {
            if (check_box_list[t].checked) {
                var remove_id = check_box_list[t].parentNode.parentNode.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.id;
                myArray.push(remove_id)
            }
        }
        if (myArray.length === 0) {
            document.getElementById("Confirm-content").innerHTML = "没有选择删除的流程！";
        } else {
            document.getElementById("Confirm-content").innerHTML = "确认要删除这" + String(myArray.length) + "个流程吗？"
        }
    }


    // 批量删除数据
    function DeleteData() {
        var myArray = []
        var check_box_list = document.getElementsByClassName("gm-radio-checkbox-input gm-checkbox-input");
        for (var t = 0; t < check_box_list.length - 1; t++) {
            if (check_box_list[t].checked) {
                var remove_id = check_box_list[t].parentNode.parentNode.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.id;
                myArray.push(remove_id)
            }
        }
        if (myArray.length === 0) {
            document.getElementById("close-model2").click();
            return myArray
        }
        console.log("myArray: ", JSON.stringify(myArray))
        var xhr = new XMLHttpRequest();
        var local_host = window.location.host;          // 获取当前IP
        xhr.open('post', "/administrative/delete_in_batches", true);
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.send("delete_list=" + JSON.stringify(myArray) + "&table_name=" + table_name);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    var JsonDate = JSON.parse(xhr.responseText);
                    alert(JsonDate["message"]);
                    window.location.reload();
                }
            }
        };
    }


    function permissions_validation(a_href, permissions_type) {
        var xhr = new XMLHttpRequest();
        var local_host = window.location.host;          // 获取当前IP
        xhr.open('post', "/system-setup/permissions_validation");
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
        xhr.send("permissions_type=" + permissions_type);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    document.getElementById("loading").style.display = "none";
                    var JsonDate = JSON.parse(xhr.responseText);
                    var permissions_flag = false;

                    for (var key in JsonDate["permissions"]) {
                        if (JsonDate["permissions"][key]) {
                            permissions_flag = true;
                            break
                        }
                    }
                    if (permissions_flag) {
                        window.location.href = a_href;
                    }
                    if (!permissions_flag) {
                        alert("您的访问权限不足！")
                    }
                }
            }
        };
    }

</script>
{% endblock %}
